package com.RMP
{
    import flash.display.*;
    import flash.events.*;

    public class RecentShell extends Sprite
    {
        var startIndexChar:String;
        var myXMLList:XMLList;
        var counter:int;
        var fadeSpeed:Number;
        var iconsArray:Array;
        var myRoot:MovieClip;
        var recentImage:RecentImage;
        var startIndexNum:int;

        public function RecentShell(param1:MovieClip, param2:Number, param3:XMLList, param4) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            myXMLList = param3;
            startIndexNum = param4;
            if (myRoot.pathNames[0] == "news")
            {
                buildNewsList();
            }
            else
            {
                buildList();
            }
            myRoot.stage.addEventListener(Event.RESIZE, onResizer);
            doResize();
            return;
        }

        function doResize() : void
        {
            var _loc_1:int = 0;
            _loc_1 = 0;
            while (_loc_1 < counter)
            {
                
                iconsArray[_loc_1].x = Math.round(_loc_1 % 3 * 4 * (myRoot.unitW + myRoot.gutterW));
                iconsArray[_loc_1].y = Math.round(Math.floor(_loc_1 / 3) * 2 * (myRoot.unitH + myRoot.gutterH));
                _loc_1++;
            }
            return;
        }

        function buildList() : void
        {
            var _loc_1:int = 0;
            var _loc_2:* = undefined;
            var _loc_3:int = 0;
            var _loc_4:String = null;
            var _loc_5:* = undefined;
            _loc_1 = myXMLList.item.length();
            _loc_2 = (startIndexNum - 1) * 6;
            counter = 0;
            iconsArray = new Array();
            _loc_3 = _loc_2;
            while (_loc_3 < _loc_1)
            {
                
                _loc_4 = myXMLList.item[_loc_3].longTitle;
                _loc_5 = myXMLList.item[_loc_3].thumbnail.@iBorder;
                recentImage = new RecentImage(myRoot, fadeSpeed, _loc_4, counter, myXMLList.item[_loc_3].@id, myXMLList.item[_loc_3].thumbnail.@icon, _loc_5);
                addChild(recentImage);
                recentImage.buttonMode = true;
                recentImage.mouseChildren = false;
                recentImage.addEventListener(MouseEvent.MOUSE_OVER, btnRollOver);
                recentImage.addEventListener(MouseEvent.MOUSE_OUT, btnRollOut);
                recentImage.addEventListener(MouseEvent.CLICK, btnClick);
                iconsArray.push(recentImage);
                var _loc_7:* = counter + 1;
                counter = _loc_7;
                if (counter == 6)
                {
                    break;
                }
                _loc_3++;
            }
            return;
        }

        function updateNewsAddress(param1:String, param2:int) : void
        {
            var incomingType:* = param1;
            var incomingId:* = param2;
            trace(incomingType + " " + incomingId);
            switch(incomingType)
            {
                case "Awards":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "awards" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Partners":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "partners" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "New York Staff":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "staff" + "/" + "new-york" + "/" + "senior-staff" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Los Angeles Staff":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "staff" + "/" + "los-angeles" + "/" + "senior-staff" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Press Publications":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "press" + "/" + "publications" + "/" + "archive" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Press Releases":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "press" + "/" + "releases" + "/" + "archive" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Lectures":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "lectures" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Books":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "books" + "/" + "archive" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Selected Text":
                {
                    myRoot.clickPathNames = [""];
                    myRoot.updateAddress("/" + "practice" + "/" + "selected-text" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Press Video":
                {
                    myRoot.updateAddress("/" + "practice" + "/" + "press" + "/" + "video" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    break;
                }
                case "Architecture":
                {
                    var _loc_5:int = 0;
                    var _loc_8:int = 0;
                    var _loc_11:int = 0;
                    var _loc_12:* = myRoot.myXML.nav.projects.tier0;
                    var _loc_10:* = new XMLList("");
                    for each (_loc_13 in _loc_12)
                    {
                        
                        var _loc_14:* = _loc_12[_loc_11];
                        with (_loc_12[_loc_11])
                        {
                            if (@label == "Architecture")
                            {
                                _loc_10[_loc_11] = _loc_13;
                            }
                        }
                    }
                    var _loc_9:* = _loc_10.tier1;
                    var _loc_7:* = new XMLList("");
                    for each (_loc_10 in _loc_9)
                    {
                        
                        var _loc_11:* = _loc_9[_loc_8];
                        with (_loc_9[_loc_8])
                        {
                            if (@label == "Name")
                            {
                                _loc_7[_loc_8] = _loc_10;
                            }
                        }
                    }
                    var _loc_6:* = _loc_7.tier2.item;
                    var _loc_4:* = new XMLList("");
                    for each (_loc_7 in _loc_6)
                    {
                        
                        var _loc_8:* = _loc_6[_loc_5];
                        with (_loc_6[_loc_5])
                        {
                            if (@id == incomingId)
                            {
                                _loc_4[_loc_5] = _loc_7;
                            }
                        }
                    }
                    if (_loc_4.@sub == "T")
                    {
                        myRoot.clickPathNames = [""];
                        myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "name" + "/" + 0 + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                    }
                    else
                    {
                        myRoot.clickPathNames = [""];
                        myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "name" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    }
                    break;
                }
                case "Products":
                {
                    var _loc_5:int = 0;
                    var _loc_8:int = 0;
                    var _loc_11:int = 0;
                    var _loc_12:* = myRoot.myXML.nav.projects.tier0;
                    var _loc_10:* = new XMLList("");
                    for each (_loc_13 in _loc_12)
                    {
                        
                        var _loc_14:* = _loc_12[_loc_11];
                        with (_loc_12[_loc_11])
                        {
                            if (@label == "Products")
                            {
                                _loc_10[_loc_11] = _loc_13;
                            }
                        }
                    }
                    var _loc_9:* = _loc_10.tier1;
                    var _loc_7:* = new XMLList("");
                    for each (_loc_10 in _loc_9)
                    {
                        
                        var _loc_11:* = _loc_9[_loc_8];
                        with (_loc_9[_loc_8])
                        {
                            if (@label == "Name")
                            {
                                _loc_7[_loc_8] = _loc_10;
                            }
                        }
                    }
                    var _loc_6:* = _loc_7.tier2.item;
                    var _loc_4:* = new XMLList("");
                    for each (_loc_7 in _loc_6)
                    {
                        
                        var _loc_8:* = _loc_6[_loc_5];
                        with (_loc_6[_loc_5])
                        {
                            if (@id == incomingId)
                            {
                                _loc_4[_loc_5] = _loc_7;
                            }
                        }
                    }
                    if (_loc_4.@sub == "T")
                    {
                        myRoot.clickPathNames = [""];
                        myRoot.updateAddress("/" + "projects" + "/" + "products" + "/" + "name" + "/" + 0 + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                    }
                    else
                    {
                        myRoot.clickPathNames = [""];
                        myRoot.updateAddress("/" + "projects" + "/" + "products" + "/" + "name" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    }
                    break;
                }
                case "Exhibitions":
                {
                    var _loc_5:int = 0;
                    var _loc_8:int = 0;
                    var _loc_11:int = 0;
                    var _loc_12:* = myRoot.myXML.nav.projects.tier0;
                    var _loc_10:* = new XMLList("");
                    for each (_loc_13 in _loc_12)
                    {
                        
                        var _loc_14:* = _loc_12[_loc_11];
                        with (_loc_12[_loc_11])
                        {
                            if (@label == "Exhibitions")
                            {
                                _loc_10[_loc_11] = _loc_13;
                            }
                        }
                    }
                    var _loc_9:* = _loc_10.tier1;
                    var _loc_7:* = new XMLList("");
                    for each (_loc_10 in _loc_9)
                    {
                        
                        var _loc_11:* = _loc_9[_loc_8];
                        with (_loc_9[_loc_8])
                        {
                            if (@label == "Name")
                            {
                                _loc_7[_loc_8] = _loc_10;
                            }
                        }
                    }
                    var _loc_6:* = _loc_7.tier2.item;
                    var _loc_4:* = new XMLList("");
                    for each (_loc_7 in _loc_6)
                    {
                        
                        var _loc_8:* = _loc_6[_loc_5];
                        with (_loc_6[_loc_5])
                        {
                            if (@id == incomingId)
                            {
                                _loc_4[_loc_5] = _loc_7;
                            }
                        }
                    }
                    if (_loc_4.@sub == "T")
                    {
                        myRoot.clickPathNames = [""];
                        myRoot.updateAddress("/" + "projects" + "/" + "exhibitions" + "/" + "name" + "/" + 0 + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                    }
                    else
                    {
                        myRoot.clickPathNames = [""];
                        myRoot.updateAddress("/" + "projects" + "/" + "exhibitions" + "/" + "name" + "/" + 0 + "/" + incomingId + "/" + 0 + "/");
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function btnRollOver(event:MouseEvent)
        {
            event.currentTarget.rollOverEvent();
            return;
        }

        function btnRollOut(event:MouseEvent)
        {
            event.currentTarget.rollOutEvent();
            return;
        }

        function buildNewsList() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:int = 0;
            var _loc_3:String = null;
            var _loc_4:String = null;
            _loc_1 = (startIndexNum - 1) * 6;
            counter = 0;
            iconsArray = new Array();
            _loc_2 = _loc_1;
            while (_loc_2 < _loc_1 + 6)
            {
                
                if (_loc_2 < myXMLList.length())
                {
                    if (myXMLList[_loc_2].@type == "New York Staff" || myXMLList[_loc_2].@type == "Los Angeles Staff" || myXMLList[_loc_2].@type == "Partner")
                    {
                        _loc_3 = myXMLList[_loc_2].@type + "<br><span class = \'myBold\'>" + myXMLList[_loc_2].shortTitle + "</span>";
                    }
                    else if (myXMLList[_loc_2].@type == "Press Publications" || myXMLList[_loc_2].@type == "Press Releases")
                    {
                        var _loc_5:* = myXMLList[_loc_2].@type + "<br>" + myXMLList[_loc_2].longTitle;
                        _loc_3 = myXMLList[_loc_2].@type + "<br>" + myXMLList[_loc_2].longTitle;
                        _loc_3 = _loc_5;
                    }
                    else if (myXMLList[_loc_2].date.@season != undefined)
                    {
                        _loc_3 = myXMLList[_loc_2].@type + "<br><span class = \'myBold\'>" + myXMLList[_loc_2].shortTitle + "</span><br>" + myXMLList[_loc_2].date.@season + " " + myXMLList[_loc_2].date.@year;
                    }
                    else if (myXMLList[_loc_2].date.@year != "-1")
                    {
                        _loc_3 = myXMLList[_loc_2].@type + "<br><span class = \'myBold\'>" + myXMLList[_loc_2].shortTitle + "</span><br>" + myXMLList[_loc_2].date.@year;
                    }
                    else
                    {
                        _loc_3 = myXMLList[_loc_2].@type + "<br><span class = \'myBold\'>" + myXMLList[_loc_2].shortTitle + "</span><br>" + "In Progress";
                    }
                    _loc_4 = myXMLList[_loc_2].thumbnail.@border;
                    if (_loc_4 == "")
                    {
                        _loc_4 = "0";
                    }
                    recentImage = new RecentImage(myRoot, fadeSpeed, _loc_3, _loc_2, myXMLList[_loc_2].@id, myXMLList[_loc_2].thumbnail.@url, _loc_4);
                    addChild(recentImage);
                    recentImage.buttonMode = true;
                    recentImage.mouseChildren = false;
                    recentImage.addEventListener(MouseEvent.MOUSE_OVER, btnRollOver);
                    recentImage.addEventListener(MouseEvent.MOUSE_OUT, btnRollOut);
                    recentImage.addEventListener(MouseEvent.CLICK, btnClick);
                    iconsArray.push(recentImage);
                    var _loc_6:* = counter + 1;
                    counter = _loc_6;
                    if (counter == 6)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                _loc_2++;
            }
            return;
        }

        function btnClick(event:MouseEvent) : void
        {
            if (myRoot.pathNames[0] == "news")
            {
                updateNewsAddress(myXMLList[event.currentTarget.idNum].@type, myXMLList[event.currentTarget.idNum].@id);
            }
            else
            {
                updateAddress(event.currentTarget.dbId);
            }
            return;
        }

        function updateAddress(param1) : void
        {
            if (myRoot.pathNames[1] == "books")
            {
                myRoot.clickPathNames = ["practice", "books", "recent", myRoot.pathNames[3], param1, 0];
                myRoot.updateAddress("/" + "practice" + "/" + "books" + "/" + "recent" + "/" + myRoot.pathNames[3] + "/" + param1 + "/" + 0 + "/");
            }
            else
            {
                switch(myRoot.pathNames[2])
                {
                    case "publications":
                    {
                        myRoot.clickPathNames = ["practice", "press", "publications", "recent", myRoot.pathNames[4], param1, 0];
                        myRoot.updateAddress("/" + "practice" + "/" + "press" + "/" + "publications" + "/" + "recent" + "/" + myRoot.pathNames[4] + "/" + param1 + "/" + 0 + "/");
                        break;
                    }
                    case "releases":
                    {
                        myRoot.clickPathNames = ["practice", "press", "releases", "recent", myRoot.pathNames[4], param1, 0];
                        myRoot.updateAddress("/" + "practice" + "/" + "press" + "/" + "releases" + "/" + "recent" + "/" + myRoot.pathNames[4] + "/" + param1 + "/" + 0 + "/");
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }

    }
}
